package org.example.Command;

import org.example.Utils.StringUtils;

import java.util.HashMap;
import java.util.Map;

public class CommandFactory {

    /**
     * 根据传入的字符串获得相应的指令
     * @param in
     * @return
     * @throws Exception
     */
    public static Command getCommand(String in) throws Exception {
        HashMap<String, String> args = StringUtils.processCommand(in);
        String start = args.get("start");
        Command command = null;
        switch (start){
            case "send":
                command = new SendMessage(in,args);
                break;
            case "recv":
                command = new RecvMessage(in,args);
                break;
            case "show":
                command = new ShowMessage(in,args);
                break;
        }
        assert command != null;
        //检查指令
        command.check();
        return command;
    }
}
